<template>
  <div class="order-detail">
    <div class="header">
      <div class="header-nav">
        <van-icon name="arrow-left" size="20" color="#f5f5f5" @click="back"/>
        <span class="header-title">{{ status }}</span>
      </div>

    </div>
    <div class="info-wrap">
      <div class="detail-card row" v-if="!isFinish">
        <div class="icon-wrap">
          <van-icon :name="icon" size="20" color="#eee"/>
        </div>
        <slot name="express" v-bind:info="info"></slot>
      </div>
    </div>
    <div class="order-list">
      <div class="shop-name">
        <div class="shop-title">
          <van-icon name="shop-o" size="18"/>
          <span>雾缘蒸汽</span>
        </div>
        <van-icon name="arrow" color="#c5c5c5" size="18"/>
      </div>
      <div v-for="(item, index) in list" :key="index">
        <order-item :order="item"/>

      </div>
      <div class="card-goods-content">
        <span class="bttom-button" @click="addCar(list)">加入购物车</span>
        <slot name="buttons" :info="info" :goods="list"></slot>
      </div>

    </div>

    <van-cell title="商品总价" :value="'¥'+info.goodsPrice"/>
    <van-cell title="优惠券"  :value="'¥'+info.couponPrice"/>
    <van-cell title="运费" :value="'¥'+info.freightPrice"/>
    <van-cell title="">
      <div>
        <span class="title">
          实付款:
        </span>
        <span>{{ '¥' + info.actualPrice }}</span>
      </div>
    </van-cell>
    <div class="order-info-wrap">
      <span>订单信息</span>
    </div>
    <van-cell title="订单编号">
      <template>
        <div>
         <span>
           {{ info.orderSn }}
         </span>
          <span class="copy" @click="copy">复制</span>
        </div>
      </template>
    </van-cell>

    <van-cell title="创建时间" :value="info.addTime "/>

    <slot name="info" v-bind:info="info"></slot>
    <div>

      <slot name="footer"></slot>
    </div>
  </div>
</template>

<script>

import OrderItem from './OrderItem'
import {Dialog, Toast} from 'vant'
import {orderDetail} from '../api/order'
import {cartAddList} from '../api/items'

export default {
  name: 'OrderDetail',
  components: {OrderItem},
  props: {
    orderId: Object,
    status: String,
    isFinish: Boolean,
    icon: {
      type: String,
      default: 'location-o'
    }
  },
  data () {
    return {
      info: {},
      list: []
    }
  },
  created () {
    this.initData()
  },
  methods: {
    addCar (goods) {
      console.log(goods)
      cartAddList(goods).then(res => {
        Dialog.alert({
          message: '加购成功',
          theme: 'round-button',
          showCancelButton: true,
          confirmButtonText: '去结算'
        }).then(() => {
          this.$router.push({name: 'cart'})
        })
      }).catch(error => {
        Toast.fail(error.data.errmsg)
      })
    },

    initData () {
      orderDetail({orderId: this.orderId}).then(res => {
        let data = res.data.data
        this.info = data.orderInfo
        this.list = data.orderGoods
      })
    },
    copy () {
      this.$copyText(this.info.orderSn).then(res => {
        Toast('拷贝成功')
      })
    },
    back () {
      this.$emit('onBack')
    }

  }

}
</script>

<style scoped>
.order-info-wrap{
  margin-top: 5px;
  color: black;
  background: white;
  padding-top: 10px;
  padding-left: 15px;
  font-weight: bold;
}
.title {
  font-size: 14px;
  color: black;
  font-weight: bold;
}

.copy {
  font-size: 4px;
  padding: 3px;
  border-radius: 10px;
  color: #E65D6E;
  border: #E65D6E solid 1px;
}

.order-detail {
  height: 100%;
}

.normal-font {
  font-weight: normal;
}

.margin-right {
  margin-right: 10px;
}

.pay-num {
  font-weight: bold;
}

.btn-add-car {
  margin: 10px 10px 10px 0;
  display: inline-block;
  font-size: 12px;
  border-radius: 15px;
  padding: 3px 6px;
  border: 1px #c5c5c5 solid;
}

.padding-bottom {
  padding-bottom: 10px;
}

.num-wrap {
  font-size: 12px;
  color: #c5c5c5;
}

.num {
  font-size: 16px;
}

.cell {
  background: white;
  padding: 5px 10px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}

.cell-float {
  background: white;
  padding: 5px 10px;
}

.order-list {
  margin-top: 10px;
  background: white;
  padding: 10px;
}

.shop-name {
  padding: 5px;
}

.header {
  background: #E65D6E;
}

.info-wrap {
  background: #E65D6E;
  padding-bottom: 10px;
}

.header-nav {
  padding: 10px 0;
  display: flex;
  flex-direction: row;
  align-items: center;
}

.header-title {
  color: #fff;
  flex: 1;
  text-align: center;
}

.detail-card {
  margin-left: 10px;
  margin-right: 10px;
  margin-bottom: 10px;
  background: white;
  padding: 8px 5px;
  border-radius: 5px;
  box-shadow: 4px 4px 40px rgba(0, 0, 0, .05);
}

.row {
  align-items: center;
  display: flex;
  flex-direction: row;
}

.user-info-name {
  font-size: 14px;
  color: black;
  font-weight: bold;
}

.user-info {
  font-size: 12px;
  color: #c5c5c5;
}

.user-info {
  margin-left: 10px;
}

.address {
  margin-top: 5px;
}

.pro-info {
  margin-top: 10px;
  background: white;
}

.shop-title {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
}

.font-light {
  color: #E65D6E;
}
.bttom-button {
  margin-right: 5px;
  padding: 5px 10px;
  border-radius: 15px;
  font-size: 12px;
  cursor: pointer;
  border: 1px #c5c5c5 solid;
}

span {
  padding: 0;
  margin: 0;
}

.icon-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 40px;
  height: 40px;
  border-radius: 20px;
  background: linear-gradient(to right, #ff6034, #ee0a24);
}
</style>
